package com.zhuhjay.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhuhjay.eduservice.entity.CrmBanner;
import com.zhuhjay.eduservice.mapper.CrmBannerMapper;
import com.zhuhjay.eduservice.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author ZhuHJay
 * @since 2022-09-07
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    @Override
    @Cacheable(value = "BANNER", key = "'BANNER_LIST'")
    public List<CrmBanner> selectBanner() {
        LambdaQueryWrapper<CrmBanner> queryWrapper = new LambdaQueryWrapper<>();
        // 最近的3条banner
        queryWrapper.orderByDesc(CrmBanner::getGmtModified).last("limit 3");
        return this.list(queryWrapper);
    }

}
